<?php
/**
 * 微信消息处理
 */
namespace App\Util;
use App\Models\Setting;
use EasyWeChat\Kernel\Messages\News;
use EasyWeChat\Kernel\Messages\NewsItem;

class WechatMessage
{
    private $_keyword = "";

    // 相应消息结构
    private $response = array();

    public function __construct($_keyword)
    {
       $this->_keyword = $_keyword;
       $this->dispose();
    }

    /**
     * 处理关键词
     */
    private function dispose()
    {
        // 应用出发关键词
        if($this->_keyword == Setting::value('app_keyword')) {
            $_news = [
                new NewsItem([
                  "title" => Setting::value('website_name'),
                  "description" => "点击进入应用",
                  "url" => route("app"),
                  "image" => asset('assets/images/share-cover.jpg')
                ])
            ];
            $this->response = new News($_news);
        }
    }

    public function response()
    {
        return $this->response;
    }
}
